conreg <- function(x, y, family = c("ls", "logit"), penalty = c("scad", 
    "mcp", "sica"), a, nlambda = 100, lambda.factor = ifelse(nobs < nvars, 0.01, 
    1e-04), lambda = NULL, lambda2 = 0, exclude, dfmax = nvars + 
    1, pmax = min(dfmax * 1.2, nvars), standardize = TRUE, eps = 1e-06, maxit = 1e+05) {
    #################################################################################
    #data setup
    family <- match.arg(family)
    penalty <- match.arg(penalty)
    this.call <- match.call()
    y <- drop(y)
    x <- as.matrix(x)
    np <- dim(x)
    nobs <- as.integer(np[1])
    nvars <- as.integer(np[2])
    vnames <- colnames(x)
    if (is.null(vnames)) 
        vnames <- paste("V", seq(nvars), sep = "")
    if (length(y) != nobs) 
        stop("x and y have different number of observations")
    #################################################################################
    #parameter setup
    if (missing(a)) 
        a <- switch(penalty, scad = 3.7, mcp = 2, sica = 0.1)
    if (lambda2 < 0) 
        stop("lambda2 must be non-negative")
    lambda2 <- max(lambda2, 1e-05)
    maxit <- as.integer(maxit)
    lam2 <- as.double(lambda2)
    isd <- as.integer(standardize)
    eps <- as.double(eps)
    dfmax <- as.integer(dfmax)
    pmax <- as.integer(pmax)
    a <- as.double(a)
    if (!missing(exclude)) {
        jd <- match(exclude, seq(nvars), 0)
        if (!all(jd > 0)) 
            stop("Some excluded variables out of range")
        jd <- as.integer(c(length(jd), jd))
    } else jd <- as.integer(0)
    #################################################################################
    #lambda setup
    nlam <- as.integer(nlambda)
    if (is.null(lambda)) {
        if (lambda.factor >= 1) 
            stop("lambda.factor should be less than 1")
        flmin <- as.double(lambda.factor)
        ulam <- double(1)
    } else {
        #flmin=1 if user define lambda
        flmin <- as.double(1)
        if (any(lambda < 0)) 
            stop("lambdas should be non-negative")
        ulam <- as.double(rev(sort(lambda)))
        nlam <- as.integer(length(lambda))
    }
    #################################################################################
    fit <- switch(family, ls = lspath(x, y, nlam, flmin, ulam, isd, eps, dfmax, 
        pmax, jd, maxit, lam2, penalty, a, nobs, nvars, vnames), logit = logitpath(x, 
        y, nlam, flmin, ulam, isd, eps, dfmax, pmax, jd, maxit, lam2, penalty, 
        a, nobs, nvars, vnames))
    if (is.null(lambda)) 
        fit$lambda <- lamfix(fit$lambda)
    fit$call <- this.call
    #################################################################################
    class(fit) <- c("conreg", class(fit))
    fit
} 
